package com.sky.controller.admin;

import com.alibaba.druid.support.json.JSONUtils;
import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 把店铺状态与redis交互
 *
 * @Author mr.Du
 * @Date 2025/5/27 2025/5/27
 */
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺的营业状态到redis
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result saveStatus(@PathVariable("status") Integer status) {
        redisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS, JSONUtils.toJSONString(status));
        return Result.success();
    }

    @GetMapping("/status")
    public Result findStatus(){
        String status = (String) redisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS);
        return Result.success(status);
    }

    @GetMapping("user/shop/status")
    public Result getStatus(){
        Object status = redisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS);
        return Result.success(status);
    }
}
